package com.boxtelecom.adapters;

import com.boxtelecom.chat.MyMessage;
import com.boxtelecom.mycircle.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ChatArrayAdapter extends ArrayAdapter<MyMessage> {
	
	private int _resources;

	public ChatArrayAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
		// TODO Auto-generated constructor stub
		_resources = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		LinearLayout layout;
		
		MyMessage aMessage = getItem(position);
		
		if(convertView == null){
			layout = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(inflater);
			vi.inflate(_resources, layout,true);
		} else {
			layout = (LinearLayout) convertView;
		}
		
		TextView userName = (TextView) layout.findViewById(R.id.userName);
		TextView userMessage = (TextView) layout.findViewById(R.id.userMessage);
		
		userName.setText(aMessage.getUserName());
		userMessage.setText(aMessage.getUserMessage());
		userMessage.setTextColor(aMessage.getColorId());
		
		return layout;
	}
}
